<?php
class admin_categoryController extends adminController{

    //首页
    public function index() {
        //获取广告位列表
        $this->list=model('advertising_category')->advertising_category();
        $this->show();  
    }

    //添加
    public function add() {
        $this->action_name='添加';
        $this->action='add';
        $this->type_list=model('advertising_category')->type_list();
        $this->show('admin_category/info'); 
    }

    public function add_save() {
        if(model('advertising_category')->info_sign($_POST['sign'])){
            $this->msg('广告标识不能重复！',0);
        }
        //录入模型处理
        $id=model('advertising_category')->add($_POST);
        $this->msg('广告位添加成功！',1);
    }

    //修改
    public function edit() {
        $id=$_GET['id'];
        $this->alert_str($id,'int');
        $this->type_list=model('advertising_category')->type_list();
        $this->info=model('advertising_category')->info($id);
        $this->type=$this->info['type'];
        $this->action_name='编辑';
        $this->action='edit';
        $this->show('admin_category/info'); 
    }

    public function edit_save() {
        $id=$_POST['id'];
        $this->alert_str($id,'int',true);
        if(model('advertising_category')->info_sign($_POST['sign'],$id)){
            $this->msg('广告标识不能重复！',0);
        }
        //录入模型处理
        model('advertising_category')->edit($_POST);
        $this->msg('广告位修改成功! ',1);
    }

    //删除
    public function del() {
        $id=intval($_POST['id']);
        $this->alert_str($id,'int',true); 
        //录入模型处理
        model('advertising_category')->del($id);
        //删除广告数据
        $list=model('advertising')->advertising_list($id);
        if(!empty($list)){
            foreach ($list as $value) {
                model('advertising')->del($value['id']);
            }
        }
        $this->msg('广告位删除成功！',1);
    }


}